package day04;

import java.sql.SQLOutput;
import java.util.Scanner;

public class StudentSystem {


    static Student[] students={
            new Student(1,"zs",18,180,"男"),
            new Student(2,"LS",19,178,"女")

    };
    static Scanner input = new Scanner(System.in);
    public static void main(String[] args) {

        while(true) {

            System.out.println("1.查看学生信息");
            System.out.println("2.输入姓名查看学生信息");
            System.out.println("3.增加学生信息");
            System.out.println("4.修改学生信息");
            System.out.println("5.删除学生信息");
            System.out.println("6.退出系统");
            System.out.println("请输入编号选择功能");
            int index = input.nextInt();
            if (index == 1) {
                selectAll();
            } else if (index == 2) {
            selectByname();
            } else if (index == 3) {
add();
            } else if (index == 4) {

            } else if (index == 5) {

            } else if (index == 6) {
                break;
            } else {
                System.out.println("没有此功能");
            }

        }
    }

    public static void selectAll() {
        if(students.length==0){
         System.out.println("没有学生信息");
         }else{
               for (int i = 0; i < students.length; i++) {
                Student student=students[i];
              System.out.println("学号："+student.sno+"姓名："+student.name+"年龄："+student.age+"性别："+student.sex);

    }
    }
}
public static void selectByname(){
    System.out.println("请输入所有查询学生姓名");
    String name=input.next();
    Student student=null;
    for (int i = 0; i < students.length; i++) {
        if(name.equals(students[i].name)){
            student=students[i];
break;
        }
    }
    if(student==null){
        System.out.println("没有此学生");
    }else{
        System.out.println(student.name);
    }
}
public static void add(){
        Student student=new Student();

        System.out.println("请输入学生编号");
        student.sno =input.nextInt();

    boolean isFind=false;
    for(int i=0;i<students.length;i++){
        if(student.sno==students[i].sno){
            isFind=true;
            break;
        }
    }
    if (isFind){
        System.out.println("学号重复");
    }else{
        System.out.println("请输入学生姓名");
        student.name =input.next();
        System.out.println("请输入学生年龄");
        student.age =input.nextInt();
        System.out.println("请输入学生身高");
        student.height =input.nextInt();
        System.out.println("请输入学生性别");
        student.sex =input.next();
        Student[] copy =new Student[students.length+1];
        for (int i = 0; i < students.length; i++) {
            copy[i]=students[i];
        }
        students = copy;
        students[students.length-1]=student;
    }




    }
}

